package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.ServiceProviderSpace;
import com.eastfair.venueservice.service.ServiceProviderSpaceService;
import com.eastfair.venueservice.vo.ServiceProviderSpaceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 展会服务商场地关系
 * </p>
 *
 * @author linan
 * @date 2022-07-15
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/serviceProviderSpace")
@Api(value = "ServiceProviderSpace", tags = "展会服务商场地关系")
public class ServiceProviderSpaceController extends SuperController<ServiceProviderSpaceService, Long, ServiceProviderSpace, ServiceProviderSpacePageQuery, ServiceProviderSpaceSaveDTO, ServiceProviderSpaceUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<ServiceProviderSpace> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ServiceProviderSpace> serviceProviderSpaceList = list.stream().map((map) -> {
            ServiceProviderSpace serviceProviderSpace = ServiceProviderSpace.builder().build();
            //TODO 请在这里完成转换
            return serviceProviderSpace;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(serviceProviderSpaceList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ServiceProviderSpacePageQuery> params) {
        ServiceProviderSpacePageQuery pageQuery = params.getModel();
        //分页处理
        if(ContextUtil.getProjectId()!=null){
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }

    /**
     * 查询服务商使用展厅
     *
     * @param serviceProviderSpaceQuery 查询服务商使用展厅
     * @return R
     */
    @ApiOperation(value = "查询服务商使用展厅", notes = "查询服务商使用展厅")
    @PostMapping("/queryServiceProviderSpace")
    public R<List<ServiceProviderSpaceVO>> queryServiceProviderSpace(@RequestBody ServiceProviderSpaceQuery serviceProviderSpaceQuery) {
        log.info("queryServiceProviderSpace - 查询服务商使用展厅 serviceProviderSpaceQuery={}", serviceProviderSpaceQuery);
        return baseService.queryExhibitionManageDetail(serviceProviderSpaceQuery);
    }

    /**
     * 查询服务商使用的所有展厅
     *
     * @param serviceProviderSpaceQuery 查询服务商使用的所有展厅
     * @return R
     */
    @ApiOperation(value = "查询服务商使用的所有展厅", notes = "查询服务商使用的所有展厅")
    @PostMapping("/queryServiceProviderAllSpace")
    public R<List<ServiceProviderSpaceVO>> queryServiceProviderAllSpace(@RequestBody ServiceProviderSpaceQuery serviceProviderSpaceQuery) {
        log.info("queryServiceProviderAllSpace - 查询服务商使用的所有展厅 serviceProviderSpaceQuery={}", serviceProviderSpaceQuery);
        return R.success(baseService.queryServiceProviderAllSpace(serviceProviderSpaceQuery));
    }
}
